﻿using LightingPlatform.Tools;
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Linq;

namespace LightingPlatform.ViewModel
{
    public interface ICloneable
    {
        object Clone();
    }

    public class LightingViewModel : NotifyingObject, ICloneable
    {
        private string _id;
        private string _series;
        private UInt32 _class;
        private UInt32 _place;
        private string _version;
        private string _lable;
        private UInt32 _orgin;

        public string ID
        {
            get { return _id; }
            set { _id = value; }
        }

        public string Series
        {
            get { return _series; }
            set
            {
                _series = value;
                this.RaisePropertyChanged("Series");
            }
        }

        public UInt32 Class
        {
            get { return _class; }
            set 
            { 
                _class = value;
                _classView = null;
            }
        }

        private string _classView;

        public string ClassView
        {
            get
            {
                if (string.IsNullOrEmpty(_classView))
                {
                    if (_class > 0)
                    {
                        ResItem item = LightingServer.Singleton.GetResourceItem(ResourceType.ProductTypes, _class);
                        if (item != null)
                            _classView = item.ItemName;
                    }
                }

                return _classView;
            }
            set
            {
                _classView = value;
                this.RaisePropertyChanged("ClassView");
            }
        }

        public UInt32 Place
        {
            get { return _place; }
            set 
            {
                _place = value;
                _placeView = null;
            }
        }

        private string _placeView;
        public string PlaceView
        {
            get
            {
                if (string.IsNullOrEmpty(_placeView))
                {
                    if (_place > 0)
                    {
                        ResItem item = LightingServer.Singleton.GetResourceItem(ResourceType.UseArea, _place);
                        if (item != null)
                            _placeView = item.ItemName;
                    }
                }

                return _placeView;
            }
            set
            {
                _placeView = value;
                this.RaisePropertyChanged("PlaceView");
            }
        }

        public string Version
        {
            get { return _version; }
            set
            {
                _version = value;
                this.RaisePropertyChanged("Version");
            }
        }


        public string Lable
        {
            get { return _lable; }
            set
            {
                _lable = value;
                this.RaisePropertyChanged("Version");
            }
        }

        public UInt32 Orgin
        {
            get { return _orgin; }
            set 
            { 
                _orgin = value;
                _orginView = null;
            }
        }

        private string _orginView;
        public string OrginView
        {
            get
            {
                if (string.IsNullOrEmpty(_orginView))
                {
                    if (_orgin > 0)
                    {
                        ResItem item = LightingServer.Singleton.GetResourceItem(ResourceType.Orgin, _orgin);
                        if (item != null)
                            _orginView = item.ItemName;
                    }
                }

                return _orginView;
            }
            set
            {
                _orginView = value;
                this.RaisePropertyChanged("OrginView");
            }
        }

        private PhysicalVM _physical;
        private OpticsVM _optics;
        private ElectricVM _electric;
        private AdapterLightingVM _adapterLighting;
        private ProjectVM _project;
        private BusinessVM _business;
        private PictureVM _picture;

        public PhysicalVM Physical
        {
            get { return _physical; }
            set
            {
                _physical = value;
                this.RaisePropertyChanged("Physical");
            }
        }

        public OpticsVM Optics
        {
            get { return _optics; }
            set
            {
                _optics = value;
                this.RaisePropertyChanged("Optics");
            }
        }

        public ElectricVM Electric
        {
            get { return _electric; }
            set
            {
                _electric = value;
                this.RaisePropertyChanged("Electric");
            }
        }

        public AdapterLightingVM AdapterLighting
        {
            get { return _adapterLighting; }
            set
            {
                _adapterLighting = value;
                this.RaisePropertyChanged("AdapterLighting");
            }
        }

        public ProjectVM Project
        {
            get { return _project; }
            set
            {
                _project = value;
                this.RaisePropertyChanged("Project");
            }
        }

        public BusinessVM Business
        {
            get { return _business; }
            set
            {
                _business = value;
                this.RaisePropertyChanged("Business");
            }
        }

        public PictureVM Picture
        {
            get { return _picture; }
            set
            {
                _picture = value;
                this.RaisePropertyChanged("Picture");
            }
        }



        public object Clone()
        {
            //private string _id;
            //private string _series;
            //private UInt32 _class;
            //private UInt32 _place;
            //private string _version;
            //private string _lable;
            //private UInt32 _orgin;
            return new LightingViewModel()
            {
                _id = _id,
                _series = _series,
                _class = _class,
                _place = _place,
                _version = _version,
                _lable = _lable,
                _orgin = _orgin,
                _physical = (PhysicalVM)_physical.Clone(),
                _optics = (OpticsVM)_optics.Clone(),
                _electric = (ElectricVM)_electric.Clone(),
                _adapterLighting = (AdapterLightingVM)_adapterLighting.Clone(),
                _project = (ProjectVM)_project.Clone(),
                _business = (BusinessVM)_business.Clone(),
                _picture = (PictureVM)_picture.Clone(),
            };
        }
    }

    public class ElectricVM : NotifyingObject, ICloneable
    {
        private string _id;
        private string _shock;
        private UInt32 _voltage;
        private string _type;
        private string _electricPower;
        private uint _lightingPower;
        private string _allPower;
        private UInt32 _controlType;

        public string ID
        {
            get { return _id; }
            set { _id = value; }
        }

        public string Shock
        {
            get { return _shock; }
            set
            {
                _shock = value;
                this.RaisePropertyChanged("Shock");
            }
        }

        public UInt32 Voltage
        {
            get { return _voltage; }
            set
            {
                _voltage = value;
                _voltageView = null;
            }
        }


        private string _voltageView;
        public string VoltageView
        {
            get
            {
                if (string.IsNullOrEmpty(_voltageView))
                {
                    if (_voltage > 0)
                    {
                        ResItem item = LightingServer.Singleton.GetResourceItem(ResourceType.WorkVoltage, _voltage);
                        if (item != null)
                            _voltageView = item.ItemName;
                    }
                }

                return _voltageView;
            }
            set
            {
                _voltageView = value;
                this.RaisePropertyChanged("VoltageView");
            }
        }

        public string Type
        {
            get { return _type; }
            set
            {
                _type = value;
                this.RaisePropertyChanged("Type");
            }
        }

        public string ElectricPower
        {
            get { return _electricPower; }
            set
            {
                _electricPower = value;
                this.RaisePropertyChanged("ElectricPower");
            }
        }

        public uint LightingPower
        {
            get { return _lightingPower; }
            set
            {
                _lightingPower = value;
                this.RaisePropertyChanged("LightingPower");
            }
        }

        public string AllPower
        {
            get { return _allPower; }
            set
            {
                _allPower = value;
                this.RaisePropertyChanged("AllPower");
            }
        }

        public UInt32 ControlType
        {
            get { return _controlType; }
            set
            {
                _controlType = value;
                _controlTypeView = null;
            }
        }

        private string _controlTypeView;
        public string ControlTypeView
        {
            get
            {
                if (string.IsNullOrEmpty(_controlTypeView))
                {
                    if (_controlType > 0)
                    {
                        ResItem item = LightingServer.Singleton.GetResourceItem(ResourceType.ControlType, _controlType);
                        if (item != null)
                            _controlTypeView = item.ItemName;
                    }
                }

                return _controlTypeView;
            }
            set
            {
                _controlTypeView = value;
                this.RaisePropertyChanged("ControlTypeView");
            }
        }

        public object Clone()
        {
            return new ElectricVM()
            {
                _id = _id,
                _shock = _shock,
                _voltage = _voltage,
                _type = _type,
                _electricPower = _electricPower,
                _lightingPower = _lightingPower,
                _allPower = _allPower,
                _controlType = _controlType,
            };
        }
    }

    public class AdapterLightingVM : NotifyingObject, ICloneable
    {
        private string _id;
        private UInt32 _class;
        private string _version;
        private string _color;
        private string _cri;
        private string _output;
        private string _pins;

        public string ID
        {
            get { return _id; }
            set { _id = value; }
        }

        public UInt32 Class
        {
            get { return _class; }
            set 
            { 
                _class = value;
                _classView = null;
            }
        }

        private string _classView;

        public string ClassView
        {
            get
            {
                if (string.IsNullOrEmpty(_classView))
                {
                    if (_class > 0)
                    {
                        ResItem item = LightingServer.Singleton.GetResourceItem(ResourceType.LightingType, _class);
                        if (item != null)
                            _classView = item.ItemName;
                    }
                }

                return _classView;
            }
            set
            {
                _classView = value;
                this.RaisePropertyChanged("ClassView");
            }
        }

        public string Version
        {
            get { return _version; }
            set
            {
                _version = value;
                this.RaisePropertyChanged("Version");
            }
        }

        public string Color
        {
            get { return _color; }
            set
            {
                _color = value;
                this.RaisePropertyChanged("Color");
            }
        }


        public string Cri
        {
            get { return _cri; }
            set
            {
                _cri = value;
                this.RaisePropertyChanged("Cri");
            }
        }

        public string Output
        {
            get { return _output; }
            set
            {
                _output = value;
                this.RaisePropertyChanged("Output");
            }
        }

        public string Pins
        {
            get { return _pins; }
            set
            {
                _pins = value;
                this.RaisePropertyChanged("Pins");
            }
        }

        public object Clone()
        {
            return new AdapterLightingVM()
            {
                _id = _id,
                _class = _class,
                _version = _version,
                _color = _color,
                _cri = _cri,
                _output = _output,
                _pins = _pins,
            };
        }
    }

    public class OpticsVM : NotifyingObject, ICloneable
    {
        private string _id;
        private UInt32 _explain;
        private string _angle;
        private string _efficiency;

        public string ID
        {
            get { return _id; }
            set { _id = value; }
        }

        public UInt32 Explain
        {
            get { return _explain; }
            set
            { 
                _explain = value;
                _explainView = null;
            }
        }

        private string _explainView;

        public string ExplainView
        {
            get
            {
                if (string.IsNullOrEmpty(_explainView))
                {
                    if (_explain > 0)
                    {
                        ResItem item = LightingServer.Singleton.GetResourceItem(ResourceType.LightingExplain, _explain);
                        if (item != null)
                            _explainView = item.ItemName;
                    }
                }

                return _explainView;
            }
            set
            {
                _explainView = value;
                this.RaisePropertyChanged("ExplainView");
            }
        }

        public string Angle
        {
            get { return _angle; }
            set
            {
                _angle = value;
                this.RaisePropertyChanged("Angle");
            }
        }


        public string Efficiency
        {
            get { return _efficiency; }
            set
            {
                _efficiency = value;
                this.RaisePropertyChanged("Efficiency");
            }
        }



        public object Clone()
        {
            return new OpticsVM()
            {
                _id = _id,
                _explain = _explain,
                _angle = _angle,
                _efficiency = _efficiency,
            };
        }
    }

    public class PhysicalVM : NotifyingObject, ICloneable
    {
        private string _id;
        private string _material;
        private string _color;
        private string _size;
        private string _defend;
        private UInt32 _impact;
        private string _weight;

        public string ID
        {
            get { return _id; }
            set { _id = value; }
        }

        public string Material
        {
            get { return _material; }
            set
            {
                _material = value;
                this.RaisePropertyChanged("Material");
            }
        }

        public string Color
        {
            get { return _color; }
            set
            {
                _color = value;
                this.RaisePropertyChanged("Color");
            }
        }

        public string Size
        {
            get { return _size; }
            set
            {
                _size = value;
                this.RaisePropertyChanged("Size");
            }
        }

        public string Defend
        {
            get { return _defend; }
            set
            {
                _defend = value;
                this.RaisePropertyChanged("Defend");
            }
        }

        public UInt32 Impact
        {
            get { return _impact; }
            set
            { 
                _impact = value;
                _impactView = null;
            }
        }

        private string _impactView;

        public string ImpactView
        {
            get
            {
                if (string.IsNullOrEmpty(_impactView))
                {
                    if (_impact > 0)
                    {
                        ResItem item = LightingServer.Singleton.GetResourceItem(ResourceType.ImpactType, _impact);
                        if (item != null)
                            _impactView = item.ItemName;
                    }
                }

                return _impactView;
            }
            set
            {
                _impactView = value;
                this.RaisePropertyChanged("ImpactView");
            }
        }

        public string Weight
        {
            get { return _weight; }
            set
            {
                _weight = value;
                this.RaisePropertyChanged("Weight");
            }
        }

        public object Clone()
        {
            return new PhysicalVM()
            {
                _id = _id,
                _material = _material,
                _color = _color,
                _size = _size,
                _defend = _defend,
                _impact = _impact,
                _weight = _weight,
            };
        }
    }

    public class PictureVM : NotifyingObject, ICloneable
    {
        private string _id;
        public string ID
        {
            get { return _id; }
            set { _id = value; }
        }

        private string _facadeView;
        public string FacadeView
        {
            get
            {
                return _facadeView;
            }
            set
            {
                _facadeView = value;
                this.RaisePropertyChanged("FacadeView");
            }
        }

        private string _sizeView;
        public string SizeView
        {
            get
            {
                return _sizeView;
            }
            set
            {
                _sizeView = value;
                this.RaisePropertyChanged("SizeView");
            }
        }

        private string _grading1View;

        public string Grading1View
        {
            get
            {
                return _grading1View;
            }
            set
            {
                _grading1View = value;
                this.RaisePropertyChanged("Grading1View");
            }
        }

        private string _liveView;
        public string LiveView
        {
            get
            {
                return _liveView;
            }
            set
            {
                _liveView = value;
                this.RaisePropertyChanged("LiveView");
            }
        }

        public byte[] UploadFacade { get; set; }
        public byte[] UploadSize { get; set; }
        public byte[] UploadGrading { get; set; }
        public byte[] UploadLive { get; set; }

        public object Clone()
        {
            return new PictureVM()
            {
                _id = _id,
                _facadeView = _facadeView,
                _sizeView = _sizeView,
                _grading1View = _grading1View,
                _liveView = _liveView,
                UploadFacade = UploadFacade,
                UploadGrading = UploadGrading,
                UploadSize = UploadSize,
                UploadLive = UploadLive
            };
        }
    }

    public class ProjectVM : NotifyingObject, ICloneable
    {
        private string _id;
        private string _parts;
        private UInt32 _setup;
        private string _size;
        private string _report;
        private string _baikup;

        public string ID
        {
            get { return _id; }
            set { _id = value; }
        }

        public string Parts
        {
            get { return _parts; }
            set
            {
                _parts = value;
                this.RaisePropertyChanged("Parts");
            }
        }


        public UInt32 Setup
        {
            get { return _setup; }
            set
            {
                _setup = value;
                _setupView = null;
            }
        }


        private string _setupView;

        public string SetupView
        {
            get
            {
                if (string.IsNullOrEmpty(_setupView))
                {
                    if (_setup > 0)
                    {
                        ResItem item = LightingServer.Singleton.GetResourceItem(ResourceType.SetupType, _setup);
                        if (item != null)
                            _setupView = item.ItemName;
                    }
                }

                return _setupView;
            }
            set
            {
                _setupView = value;
                this.RaisePropertyChanged("SetupView");
            }
        }


        public string Size
        {
            get { return _size; }
            set
            {
                _size = value;
                this.RaisePropertyChanged("Size");
            }
        }

        public string Report
        {
            get { return _report; }
            set
            {
                _report = value;
                this.RaisePropertyChanged("Report");
            }
        }

        public string Baikup
        {
            get { return _baikup; }
            set
            {
                _baikup = value;
                this.RaisePropertyChanged("Baikup");
            }
        }

        public object Clone()
        {
            return new ProjectVM()
            {
                _id = _id,
                _parts = _parts,
                _setup = _setup,
                _size = _size,
                _report = _report,
                _baikup = _baikup,
            };
        }
    }

    public class BusinessVM : NotifyingObject, ICloneable
    {
        private string _id;
        private string _in;
        private string _market;
        private string _out;
        private string _delievery;

        public string ID
        {
            get { return _id; }
            set { _id = value; }
        }

        public string In
        {
            get { return _in; }
            set
            {
                _in = value;
                this.RaisePropertyChanged("In");
            }
        }

        public string Market
        {
            get { return _market; }
            set
            {
                _market = value;
                this.RaisePropertyChanged("Market");
            }
        }

        public string Out
        {
            get { return _out; }
            set
            {
                _out = value;
                this.RaisePropertyChanged("Out");
            }
        }

        public string Delievery
        {
            get { return _delievery; }
            set
            {
                _delievery = value;
                this.RaisePropertyChanged("Delievery");
            }
        }

        public object Clone()
        {
            return new BusinessVM()
            {
                _id = _id,
                _in = _in,
                _market = _market,
                _out = _out,
                _delievery = _delievery,
            };
        }
    }
}













